﻿using System.Collections.Generic;
using Engine;
using Engine.Graphics;
using Game;
using Mekiasm.Dust;
using Mekiasm.Ignot;
using Mekiasm.Machines;

namespace Mekiasm
{
    public class MekCraftTable : Item, Interface.IDynamicCraft
    {
        public static int Index;
        public int[] FuelCraftSlotIndies => new int[0];
        public int[] CraftSlotIndies => new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
        public int[] ResultSlotIndies => new int[] { 10 };
        public int[] RemainSlotIndies => new int[] { 9 };
        public Point2 CraftSize => new Point2(3,3);
        public int SlotsCount => 11;
        public int BlockValue => blockValue;
        public BlockMesh m_blockMesh = new BlockMesh();
        public BlockMesh m_standaloneBlockMesh = new BlockMesh();

        public MekCraftTable() : base("Mek工作台")
        {
            
            Model model = ContentManager.Get<Model>("Models/CraftingTable");
            Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("CraftingTable", true).ParentBone);
            this.m_blockMesh.AppendModelMeshPart(model.FindMesh("CraftingTable", true).MeshParts[0], boneAbsoluteTransform * Matrix.CreateTranslation(0.5f, 0f, 0.5f), false, false, false, false, Color.White);
            this.m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("CraftingTable", true).MeshParts[0], boneAbsoluteTransform * Matrix.CreateTranslation(0f, -0.5f, 0f), false, false, false, false, Color.White);
        }
        public override int GetFaceTextureSlot(int face, int value)
        {
            return 27;
        }
        public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
        {
            BlocksManager.DrawMeshBlock(primitivesRenderer, m_standaloneBlockMesh, Color.LightMagenta, size, ref matrix, environmentData);
        }
        public override void GetProceduralCraftingRecipes(List<CraftingRecipe> recipes)
        {
            recipes.Add(new CraftingRecipe() { Ingredients = new string[] {
                ILibrary.GetCraftId(PlanksBlock.Index),ILibrary.GetCraftId(CopperIngotBlock.Index),ILibrary.GetCraftId(PlanksBlock.Index),
                ILibrary.GetCraftId(PlanksBlock.Index),ILibrary.GetCraftId(PlanksBlock.Index),ILibrary.GetCraftId(PlanksBlock.Index),
                "","",""
            }, ResultCount = 1, ResultValue = Index, Description = "合成Mek工作台", RequiredPlayerLevel = 1f });
        }
        public override bool IsInteractive(SubsystemTerrain subsystemTerrain, int value)
        {
            return true;
        }
        public override void GenerateTerrainVertices(Block block, BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z)
        {
            generator.GenerateShadedMeshVertices(block, x, y, z, m_blockMesh, Color.LightMagenta, null, null, geometry.SubsetOpaque);
        }
        public override bool OnUse(Ray3 aim, ComponentMiner componentMiner, TerrainRaycastResult? raycast)
        {
            return false;
        }
        public override void OnBlockAdded(SubsystemBlockBehavior blockBehavior, int value, int oldValue, int x, int y, int z)
        {
            Point3 point = new Point3(x, y, z);
            ILibrary.AddBlockEntity(DisplayName, x, y, z);
        }
        public override void OnBlockRemoved(SubsystemBlockBehavior blockBehavior, int value, int newValue, int x, int y, int z)
        {
            ILibrary.RemoveBlockEntity(x, y, z);
        }
        public override bool IsFaceTransparent(SubsystemTerrain subsystemTerrain, int face, int value)
        {
            return true;
        }
        public override bool OnInteract(SubsystemBlockBehavior blockBehavior, TerrainRaycastResult raycastResult, ComponentMiner componentMiner)
        {
            ComponentMekCraftTable mcomponent = ILibrary.SubsystemBlockEntities.GetBlockEntity(raycastResult.CellFace.X, raycastResult.CellFace.Y, raycastResult.CellFace.Z).Entity.FindComponent<ComponentMekCraftTable>(true);
            componentMiner.ComponentPlayer.ComponentGui.ModalPanelWidget = new MekCraftTableWidget(mcomponent, componentMiner);
            return true;

        }

        public override BlockDigMethod GetDigMethod(int value)
        {
            return BlockDigMethod.Hack;
        }

        public void GenerateRecipes(List<MekRecipe> mekRecipe)
        {
            foreach (var c in CraftingRecipesManager.Recipes)
            {
                if (c.RequiredHeatLevel == 0f)
                {
                    var r = new MekRecipe(3, 0, 1, 1);
                    for (int i = 0; i < c.Ingredients.Length; i++)
                    {
                        r.SetIngredian(i, c.Ingredients[i]);
                    }
                    string s = BlocksManager.Blocks[Terrain.ExtractContents(c.ResultValue)].GetDisplayName(null, c.ResultValue);
                    r.SetName($"工作台合成 {s}");
                    r.SetDescriction(c.Description);
                    r.SetRemain(0, c.RemainsValue, c.RemainsCount);
                    r.SetResult(0, c.ResultValue, c.ResultCount);
                    r.SetRequirePlayerLevel(c.RequiredPlayerLevel);
                    r.Message = c.Message;
                    mekRecipe.Add(r);
                }
            }

            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("铁板")
                .SetIngredian(0, ILibrary.GetCraftId(IronIngotBlock.Index)).SetIngredian(1, ILibrary.GetCraftId(ForgingHammer.Index))
                .SetResult(0, IronPlate.Index).SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("铁质外壳")
                .SetIngredian(0, ILibrary.GetCraftId(IronPlate.Index)).SetIngredian(1, ILibrary.GetCraftId(ForgingHammer.Index))
                .SetResult(0, IronShell.Index).SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("锡板")
                .SetIngredian(0, ILibrary.GetCraftId(TinIngnot.Index)).SetIngredian(1, ILibrary.GetCraftId(ForgingHammer.Index))
                .SetResult(0, TinPlate.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("锡质外壳")
                .SetIngredian(0, ILibrary.GetCraftId(TinPlate.Index)).SetIngredian(1, ILibrary.GetCraftId(ForgingHammer.Index))
                .SetResult(0, TinShell.Index).SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("铜板")
                .SetIngredian(0, ILibrary.GetCraftId(CopperIngotBlock.Index)).SetIngredian(1, ILibrary.GetCraftId(ForgingHammer.Index))
                .SetResult(0, CopperPlate.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("青铜板")
                .SetIngredian(0, ILibrary.GetCraftId(BronzeIngot.Index)).SetIngredian(1, ILibrary.GetCraftId(ForgingHammer.Index))
                .SetResult(0, BronzePlate.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("青铜质外壳")
                .SetIngredian(0, ILibrary.GetCraftId(BronzePlate.Index)).SetIngredian(1, ILibrary.GetCraftId(ForgingHammer.Index))
                .SetResult(0, BronzeShell.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("线圈")
                .SetIngredian(0, ILibrary.GetCraftId(CopperCable.Index)).SetIngredian(1, ILibrary.GetCraftId(CopperCable.Index)).SetIngredian(2, ILibrary.GetCraftId(CopperCable.Index))
                .SetIngredian(3, ILibrary.GetCraftId(CopperCable.Index)).SetIngredian(4, ILibrary.GetCraftId(IronIngotBlock.Index)).SetIngredian(5, ILibrary.GetCraftId(CopperCable.Index))
                .SetIngredian(6, ILibrary.GetCraftId(CopperCable.Index)).SetIngredian(7, ILibrary.GetCraftId(CopperCable.Index)).SetIngredian(8, ILibrary.GetCraftId(CopperCable.Index))
                .SetResult(0, Coil.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("金属成型机")
                .SetIngredian(1, ILibrary.GetCraftId(BasicControlCircuit.Index))
                .SetIngredian(3, ILibrary.GetCraftId(ToolBox.Index)).SetIngredian(4, ILibrary.GetCraftId(BasicMachineCasing.Index)).SetIngredian(5, ILibrary.GetCraftId(ToolBox.Index))
                .SetIngredian(6, ILibrary.GetCraftId(Coil.Index)).SetIngredian(7, ILibrary.GetCraftId(Coil.Index)).SetIngredian(8, ILibrary.GetCraftId(Coil.Index))
                .SetResult(0, MetalFomer.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("锻造锤")
                .SetIngredian(0, ILibrary.GetCraftId(CopperIngotBlock.Index)).SetIngredian(1, ILibrary.GetCraftId(CopperIngotBlock.Index))
                .SetIngredian(2, ILibrary.GetCraftId(CopperIngotBlock.Index)).SetIngredian(3, ILibrary.GetCraftId(CopperIngotBlock.Index))
                .SetIngredian(4, ILibrary.GetCraftId(StickBlock.Index)).SetIngredian(5, ILibrary.GetCraftId(CopperIngotBlock.Index))
                .SetIngredian(7, ILibrary.GetCraftId(CopperIngotBlock.Index))
                .SetResult(0, ForgingHammer.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("机械外壳")
                .SetIngredian(0, ILibrary.GetCraftId(IronPlate.Index)).SetIngredian(1, ILibrary.GetCraftId(IronPlate.Index))
                .SetIngredian(2, ILibrary.GetCraftId(IronPlate.Index)).SetIngredian(3, ILibrary.GetCraftId(IronPlate.Index))
                .SetIngredian(5, ILibrary.GetCraftId(IronPlate.Index)).SetIngredian(6, ILibrary.GetCraftId(IronPlate.Index))
                .SetIngredian(7, ILibrary.GetCraftId(IronPlate.Index)).SetIngredian(8, ILibrary.GetCraftId(IronPlate.Index))
                .SetResult(0, BasicMachineCasing.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("铁炉")
                .SetIngredian(0, ILibrary.GetCraftId(IronPlate.Index)).SetIngredian(1, ILibrary.GetCraftId(IronPlate.Index))
                .SetIngredian(2, ILibrary.GetCraftId(IronPlate.Index)).SetIngredian(3, ILibrary.GetCraftId(IronPlate.Index))
                .SetIngredian(5, ILibrary.GetCraftId(IronPlate.Index)).SetIngredian(6, ILibrary.GetCraftId(IronPlate.Index))
                .SetIngredian(4, ILibrary.GetCraftId(FurnaceBlock.Index))
                .SetIngredian(7, ILibrary.GetCraftId(IronPlate.Index)).SetIngredian(8, ILibrary.GetCraftId(IronPlate.Index))
                .SetResult(0, IronFurnace.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("木龙头")
                .SetIngredian(1, ILibrary.GetCraftId(PlanksBlock.Index)).SetIngredian(3, ILibrary.GetCraftId(PlanksBlock.Index))
                .SetIngredian(4, ILibrary.GetCraftId(PlanksBlock.Index)).SetIngredian(5, ILibrary.GetCraftId(PlanksBlock.Index))
                .SetIngredian(6, ILibrary.GetCraftId(PlanksBlock.Index))
                .SetResult(0, TreeTap.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("风箱")
                .SetIngredian(0, ILibrary.GetCraftId(LeatherBlock.Index)).SetIngredian(1, ILibrary.GetCraftId(LeatherBlock.Index)).SetIngredian(2, ILibrary.GetCraftId(LeatherBlock.Index))
                .SetIngredian(3, ILibrary.GetCraftId(LeatherBlock.Index)).SetIngredian(5, ILibrary.GetCraftId(LeatherBlock.Index))
                .SetIngredian(6, ILibrary.GetCraftId(StickBlock.Index)).SetIngredian(7, ILibrary.GetCraftId(LeatherBlock.Index)).SetIngredian(8, ILibrary.GetCraftId(StickBlock.Index))
                .SetResult(0, Bellows.Index)
                .SetRemainNeedCheck());

            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("板材切割剪刀")
                .SetIngredian(0, ILibrary.GetCraftId(IronPlate.Index)).SetIngredian(2, ILibrary.GetCraftId(IronPlate.Index))
                .SetIngredian(4, ILibrary.GetCraftId(IronPlate.Index)).SetIngredian(6, ILibrary.GetCraftId(IronIngotBlock.Index))
                .SetIngredian(8, ILibrary.GetCraftId(IronIngotBlock.Index))
                .SetResult(0, Cutter.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("铜质导线")
                .SetIngredian(0, ILibrary.GetCraftId(CopperPlate.Index)).SetIngredian(1, ILibrary.GetCraftId(Cutter.Index))
                .SetResult(0, CopperCable.Index, 3)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("绝缘铜质导线")
                .SetIngredian(0, ILibrary.GetCraftId(CopperCable.Index)).SetIngredian(1, ILibrary.GetCraftId(Rubber.Index))
                .SetResult(0, InsulatedCopperCable.Index, 3)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("锡质导线")
                .SetIngredian(0, ILibrary.GetCraftId(TinPlate.Index)).SetIngredian(1, ILibrary.GetCraftId(Cutter.Index))
                .SetResult(0, TinCable.Index, 3)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("绝缘锡质导线")
                .SetIngredian(0, ILibrary.GetCraftId(TinCable.Index)).SetIngredian(1, ILibrary.GetCraftId(Rubber.Index))
                .SetResult(0, InsulatedTinCable.Index, 3)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("低级能量导线")
                .SetIngredian(0, ILibrary.GetCraftId(CopperCable.Index)).SetIngredian(1, ILibrary.GetCraftId(CopperCable.Index)).SetIngredian(2, ILibrary.GetCraftId(CopperCable.Index))
                .SetIngredian(3, ILibrary.GetCraftId(CopperCable.Index)).SetIngredian(4, ILibrary.GetCraftId(Rubber.Index)).SetIngredian(5, ILibrary.GetCraftId(CopperCable.Index))
                .SetIngredian(6, ILibrary.GetCraftId(CopperCable.Index)).SetIngredian(7, ILibrary.GetCraftId(CopperCable.Index)).SetIngredian(8, ILibrary.GetCraftId(CopperCable.Index))
                .SetResult(0, BaseElectricWire.Index, 8)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("中级能量导线")
                .SetIngredian(0, ILibrary.GetCraftId(BaseElectricWire.Index)).SetIngredian(1, ILibrary.GetCraftId(BaseElectricWire.Index)).SetIngredian(2, ILibrary.GetCraftId(BaseElectricWire.Index))
                .SetIngredian(3, ILibrary.GetCraftId(Rubber.Index)).SetIngredian(4, ILibrary.GetCraftId(Rubber.Index)).SetIngredian(5, ILibrary.GetCraftId(Rubber.Index))
                .SetIngredian(6, ILibrary.GetCraftId(BaseElectricWire.Index)).SetIngredian(7, ILibrary.GetCraftId(BaseElectricWire.Index)).SetIngredian(8, ILibrary.GetCraftId(BaseElectricWire.Index))
                .SetResult(0, AdvanceElectricWire.Index, 6)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("高级能量导线")
                .SetIngredian(0, ILibrary.GetCraftId(AdvanceElectricWire.Index)).SetIngredian(1, ILibrary.GetCraftId(AdvanceElectricWire.Index)).SetIngredian(2, ILibrary.GetCraftId(AdvanceElectricWire.Index))
                .SetIngredian(3, ILibrary.GetCraftId(Rubber.Index)).SetIngredian(4, ILibrary.GetCraftId(Rubber.Index)).SetIngredian(5, ILibrary.GetCraftId(Rubber.Index))
                .SetIngredian(6, ILibrary.GetCraftId(AdvanceElectricWire.Index)).SetIngredian(7, ILibrary.GetCraftId(AdvanceElectricWire.Index)).SetIngredian(8, ILibrary.GetCraftId(AdvanceElectricWire.Index))
                .SetResult(0, EliteElectricWire.Index, 6)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("终极能量导线")
                .SetIngredian(0, ILibrary.GetCraftId(EliteElectricWire.Index)).SetIngredian(1, ILibrary.GetCraftId(EliteElectricWire.Index)).SetIngredian(2, ILibrary.GetCraftId(EliteElectricWire.Index))
                .SetIngredian(3, ILibrary.GetCraftId(Rubber.Index)).SetIngredian(4, ILibrary.GetCraftId(Rubber.Index)).SetIngredian(5, ILibrary.GetCraftId(Rubber.Index))
                .SetIngredian(6, ILibrary.GetCraftId(EliteElectricWire.Index)).SetIngredian(7, ILibrary.GetCraftId(EliteElectricWire.Index)).SetIngredian(8, ILibrary.GetCraftId(EliteElectricWire.Index))
                .SetResult(0, UltimateElectricWire.Index, 6)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("Mek配方谱")
                .SetIngredian(0, ILibrary.GetCraftId(LeatherBlock.Index)).SetIngredian(1, ILibrary.GetCraftId(Paper.Index))
                .SetIngredian(3, ILibrary.GetCraftId(LeatherBlock.Index)).SetIngredian(4, ILibrary.GetCraftId(Paper.Index))
                .SetIngredian(6, ILibrary.GetCraftId(LeatherBlock.Index)).SetIngredian(7, ILibrary.GetCraftId(Paper.Index))
                .SetResult(0, MekCraftBook.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("充电电池")
                .SetIngredian(1, ILibrary.GetCraftId(InsulatedTinCable.Index))
                .SetIngredian(3, ILibrary.GetCraftId(TinShell.Index)).SetIngredian(4, ILibrary.GetCraftId(TinIngnot.Index)).SetIngredian(5, ILibrary.GetCraftId(TinShell.Index))
                .SetIngredian(6, ILibrary.GetCraftId(TinShell.Index)).SetIngredian(7, ILibrary.GetCraftId(CoalChunkBlock.Index)).SetIngredian(8, ILibrary.GetCraftId(TinShell.Index))
                .SetResult(0, Battery.Index)
                .SetRemainNeedCheck());

            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("火力发电机")
                .SetIngredian(1, ILibrary.GetCraftId(Battery.Index))
                .SetIngredian(3, ILibrary.GetCraftId(IronPlate.Index)).SetIngredian(4, ILibrary.GetCraftId(IronPlate.Index)).SetIngredian(5, ILibrary.GetCraftId(IronPlate.Index))
                .SetIngredian(7, ILibrary.GetCraftId(IronFurnace.Index))
                .SetResult(0, MekCoalGenerator.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("空的流体单元")
                .SetIngredian(1, ILibrary.GetCraftId(TinIngnot.Index))
                .SetIngredian(3, ILibrary.GetCraftId(TinIngnot.Index)).SetIngredian(5, ILibrary.GetCraftId(TinIngnot.Index))
                .SetIngredian(7, ILibrary.GetCraftId(TinIngnot.Index))
                .SetResult(0, EmptyFluidCell.Index, 8)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("空的气体单元")
                .SetIngredian(1, ILibrary.GetCraftId(IronIngotBlock.Index))
                .SetIngredian(3, ILibrary.GetCraftId(IronIngotBlock.Index)).SetIngredian(5, ILibrary.GetCraftId(IronIngotBlock.Index))
                .SetIngredian(7, ILibrary.GetCraftId(IronIngotBlock.Index))
                .SetResult(0, EmptyGasCell.Index, 8)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("基础控制电路")
                .SetIngredian(0, ILibrary.GetCraftId(InsulatedCopperCable.Index)).SetIngredian(1, ILibrary.GetCraftId(InsulatedCopperCable.Index)).SetIngredian(2, ILibrary.GetCraftId(InsulatedCopperCable.Index))
                .SetIngredian(3, ILibrary.GetCraftId(IronIngotBlock.Index)).SetIngredian(4, ILibrary.GetCraftId(GermaniumOreChunkBlock.Index)).SetIngredian(5, ILibrary.GetCraftId(IronIngotBlock.Index))
                .SetIngredian(6, ILibrary.GetCraftId(InsulatedCopperCable.Index)).SetIngredian(7, ILibrary.GetCraftId(IronIngotBlock.Index)).SetIngredian(8, ILibrary.GetCraftId(InsulatedCopperCable.Index))
                .SetResult(0, BasicControlCircuit.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("高级控制电路")
                .SetIngredian(0, ILibrary.GetCraftId(GermaniumOreChunkBlock.Index)).SetIngredian(1, ILibrary.GetCraftId(BasicControlCircuit.Index)).SetIngredian(0, ILibrary.GetCraftId(GermaniumOreChunkBlock.Index))
                .SetResult(0, AdvancedControlCircuit.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("纸")
                .SetIngredian(0, ILibrary.GetCraftId(SawDust.Index)).SetIngredian(1, ILibrary.GetCraftId(SawDust.Index)).SetIngredian(2, ILibrary.GetCraftId(SawDust.Index))
                .SetResult(0, Paper.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("调整器")
                .SetIngredian(0, ILibrary.GetCraftId(GermaniumOreChunkBlock.Index)).SetIngredian(1, ILibrary.GetCraftId(Battery.Index)).SetIngredian(2, ILibrary.GetCraftId(GermaniumOreChunkBlock.Index))
                .SetIngredian(4, ILibrary.GetCraftId(StickBlock.Index))
                .SetResult(0, Configurator.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("Mek合成谱")
                .SetIngredian(0, ILibrary.GetCraftId(Paper.Index)).SetIngredian(1, ILibrary.GetCraftId(BasicControlCircuit.Index))
                .SetResult(0, MekCraftBook.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("钢质框架")
                .SetIngredian(0, ILibrary.GetCraftId(SteelIgnot.Index)).SetIngredian(1, ILibrary.GetCraftId(GlassBlock.Index)).SetIngredian(2, ILibrary.GetCraftId(SteelIgnot.Index))
                .SetIngredian(3, ILibrary.GetCraftId(GlassBlock.Index)).SetIngredian(4, ILibrary.GetCraftId(TinIngnot.Index)).SetIngredian(5, ILibrary.GetCraftId(GlassBlock.Index))
                .SetIngredian(6, ILibrary.GetCraftId(SteelIgnot.Index)).SetIngredian(7, ILibrary.GetCraftId(GlassBlock.Index)).SetIngredian(8, ILibrary.GetCraftId(SteelIgnot.Index))
                .SetResult(0, SteelFrame.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("粉碎机")
                .SetIngredian(0, ILibrary.GetCraftId(GermaniumOreChunkBlock.Index)).SetIngredian(1, ILibrary.GetCraftId(BasicControlCircuit.Index)).SetIngredian(2, ILibrary.GetCraftId(GermaniumOreChunkBlock.Index))
                .SetIngredian(3, ILibrary.GetCraftId(MagmaBucketBlock.Index)).SetIngredian(4, ILibrary.GetCraftId(SteelFrame.Index)).SetIngredian(5, ILibrary.GetCraftId(MagmaBucketBlock.Index))
                .SetIngredian(6, ILibrary.GetCraftId(GermaniumOreChunkBlock.Index)).SetIngredian(7, ILibrary.GetCraftId(BasicControlCircuit.Index)).SetIngredian(8, ILibrary.GetCraftId(GermaniumOreChunkBlock.Index))
                .SetResult(0, Crusher.Index).SetRemain(0, EmptyBucketBlock.Index, 2)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("物流整理机")
                .SetIngredian(0, ILibrary.GetCraftId(IronIngotBlock.Index)).SetIngredian(1, ILibrary.GetCraftId(PistonBlock.Index)).SetIngredian(2, ILibrary.GetCraftId(IronIngotBlock.Index))
                .SetIngredian(3, ILibrary.GetCraftId(IronIngotBlock.Index)).SetIngredian(4, ILibrary.GetCraftId(BasicControlCircuit.Index)).SetIngredian(5, ILibrary.GetCraftId(IronIngotBlock.Index))
                .SetIngredian(6, ILibrary.GetCraftId(IronIngotBlock.Index)).SetIngredian(7, ILibrary.GetCraftId(IronIngotBlock.Index)).SetIngredian(8, ILibrary.GetCraftId(IronIngotBlock.Index))
                .SetResult(0, LogisticalSorter.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("富集仓")
                .SetIngredian(0, ILibrary.GetCraftId(GermaniumOreChunkBlock.Index)).SetIngredian(1, ILibrary.GetCraftId(BasicControlCircuit.Index)).SetIngredian(2, ILibrary.GetCraftId(GermaniumOreChunkBlock.Index))
                .SetIngredian(3, ILibrary.GetCraftId(IronIngotBlock.Index)).SetIngredian(4, ILibrary.GetCraftId(SteelFrame.Index)).SetIngredian(5, ILibrary.GetCraftId(IronIngotBlock.Index))
                .SetIngredian(6, ILibrary.GetCraftId(GermaniumOreChunkBlock.Index)).SetIngredian(7, ILibrary.GetCraftId(BasicControlCircuit.Index)).SetIngredian(8, ILibrary.GetCraftId(GermaniumOreChunkBlock.Index))
                .SetResult(0, MekEnrich.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("电解核心")
                .SetIngredian(0, ILibrary.GetCraftId(InsulatedCopperCable.Index)).SetIngredian(1, ILibrary.GetCraftId(IronDust.Index)).SetIngredian(2, ILibrary.GetCraftId(InsulatedCopperCable.Index))
                .SetIngredian(3, ILibrary.GetCraftId(SteelDust.Index)).SetIngredian(4, ILibrary.GetCraftId(SteelFrame.Index)).SetIngredian(5, ILibrary.GetCraftId(SteelDust.Index))
                .SetIngredian(6, ILibrary.GetCraftId(InsulatedCopperCable.Index)).SetIngredian(7, ILibrary.GetCraftId(TinDust.Index)).SetIngredian(8, ILibrary.GetCraftId(InsulatedCopperCable.Index))
                .SetResult(0, ElectrolyticCore.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("电解分离器")
                .SetIngredian(0, ILibrary.GetCraftId(IronIngotBlock.Index)).SetIngredian(1, ILibrary.GetCraftId(GermaniumOreChunkBlock.Index)).SetIngredian(2, ILibrary.GetCraftId(IronIngotBlock.Index))
                .SetIngredian(3, ILibrary.GetCraftId(InsulatedCopperCable.Index)).SetIngredian(4, ILibrary.GetCraftId(ElectrolyticCore.Index)).SetIngredian(5, ILibrary.GetCraftId(InsulatedCopperCable.Index))
                .SetIngredian(6, ILibrary.GetCraftId(IronIngotBlock.Index)).SetIngredian(7, ILibrary.GetCraftId(GermaniumOreChunkBlock.Index)).SetIngredian(8, ILibrary.GetCraftId(IronIngotBlock.Index))
                .SetResult(0, MekElectrolyzer.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("充电台")
                .SetIngredian(0, ILibrary.GetCraftId(PressurePlateBlock.Index)).SetIngredian(1, ILibrary.GetCraftId(PressurePlateBlock.Index)).SetIngredian(2, ILibrary.GetCraftId(PressurePlateBlock.Index))
                .SetIngredian(3, ILibrary.GetCraftId(SteelIgnot.Index)).SetIngredian(4, ILibrary.GetCraftId(Battery.Index)).SetIngredian(5, ILibrary.GetCraftId(SteelIgnot.Index))
                .SetResult(0, ChargePad.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("风力发电机")
                .SetIngredian(1, ILibrary.GetCraftId(TinIngnot.Index))
                .SetIngredian(3, ILibrary.GetCraftId(SteelIgnot.Index)).SetIngredian(4, ILibrary.GetCraftId(GermaniumOreChunkBlock.Index)).SetIngredian(5, ILibrary.GetCraftId(SteelIgnot.Index))
                .SetIngredian(6, ILibrary.GetCraftId(Battery.Index)).SetIngredian(7, ILibrary.GetCraftId(BasicControlCircuit.Index)).SetIngredian(8, ILibrary.GetCraftId(Battery.Index))
                .SetResult(0, WindPowerGenerator.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("冶金灌注机")
                .SetIngredian(0, ILibrary.GetCraftId(IronIngotBlock.Index)).SetIngredian(1, ILibrary.GetCraftId(FurnaceBlock.Index)).SetIngredian(2, ILibrary.GetCraftId(IronIngotBlock.Index))
                .SetIngredian(3, ILibrary.GetCraftId(RedStoneDust.Index)).SetIngredian(4, ILibrary.GetCraftId(OsmiumIngot.Index)).SetIngredian(5, ILibrary.GetCraftId(RedStoneDust.Index))
                .SetIngredian(6, ILibrary.GetCraftId(IronIngotBlock.Index)).SetIngredian(7, ILibrary.GetCraftId(FurnaceBlock.Index)).SetIngredian(8, ILibrary.GetCraftId(IronIngotBlock.Index))
                .SetResult(0, MetallurgicInfuser.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("原子分解机")
                .SetIngredian(0, ILibrary.GetCraftId(EnrichedAlloy.Index)).SetIngredian(1, ILibrary.GetCraftId(Battery.Index)).SetIngredian(2, ILibrary.GetCraftId(EnrichedAlloy.Index))
                .SetIngredian(3, ILibrary.GetCraftId(EnrichedAlloy.Index)).SetIngredian(4, ILibrary.GetCraftId(AtomicAlloy.Index)).SetIngredian(5, ILibrary.GetCraftId(EnrichedAlloy.Index))
                .SetIngredian(7, ILibrary.GetCraftId(RefinedObsidianIgnot.Index))
                .SetResult(0, AtomicDecomposer.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("传送核心")
                 .SetIngredian(0, ILibrary.GetCraftId(Crystal.Index)).SetIngredian(1, ILibrary.GetCraftId(AtomicAlloy.Index)).SetIngredian(2, ILibrary.GetCraftId(Crystal.Index))
                 .SetIngredian(3, ILibrary.GetCraftId(GoldIgnot.Index)).SetIngredian(4, ILibrary.GetCraftId(DiamondChunkBlock.Index)).SetIngredian(5, ILibrary.GetCraftId(GoldIgnot.Index))
                 .SetIngredian(6, ILibrary.GetCraftId(Crystal.Index)).SetIngredian(7, ILibrary.GetCraftId(AtomicAlloy.Index)).SetIngredian(8, ILibrary.GetCraftId(Crystal.Index))
                 .SetResult(0, TransmitCore.Index)
                 .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("便携式传送器")
                .SetIngredian(1, ILibrary.GetCraftId(Battery.Index))
                .SetIngredian(3, ILibrary.GetCraftId(BasicControlCircuit.Index)).SetIngredian(4, ILibrary.GetCraftId(TransmitCore.Index)).SetIngredian(5, ILibrary.GetCraftId(BasicControlCircuit.Index))
                .SetIngredian(7, ILibrary.GetCraftId(Battery.Index))
                .SetResult(0, TransmitItem.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("传送框架")
                 .SetIngredian(0, ILibrary.GetCraftId(RefinedObsidianIgnot.Index)).SetIngredian(1, ILibrary.GetCraftId(RefinedObsidianIgnot.Index)).SetIngredian(2, ILibrary.GetCraftId(RefinedObsidianIgnot.Index))
                 .SetIngredian(3, ILibrary.GetCraftId(RefinedObsidianIgnot.Index)).SetIngredian(4, ILibrary.GetCraftId(GoldIgnot.Index)).SetIngredian(5, ILibrary.GetCraftId(RefinedObsidianIgnot.Index))
                 .SetIngredian(6, ILibrary.GetCraftId(RefinedObsidianIgnot.Index)).SetIngredian(7, ILibrary.GetCraftId(RefinedObsidianIgnot.Index)).SetIngredian(8, ILibrary.GetCraftId(RefinedObsidianIgnot.Index))
                 .SetResult(0, TransmitBox.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("传送机")
                 .SetIngredian(0, ILibrary.GetCraftId(BasicControlCircuit.Index)).SetIngredian(1, ILibrary.GetCraftId(SteelFrame.Index)).SetIngredian(2, ILibrary.GetCraftId(BasicControlCircuit.Index))
                 .SetIngredian(3, ILibrary.GetCraftId(SteelFrame.Index)).SetIngredian(4, ILibrary.GetCraftId(TransmitCore.Index)).SetIngredian(5, ILibrary.GetCraftId(SteelFrame.Index))
                 .SetIngredian(6, ILibrary.GetCraftId(BasicControlCircuit.Index)).SetIngredian(7, ILibrary.GetCraftId(SteelFrame.Index)).SetIngredian(8, ILibrary.GetCraftId(BasicControlCircuit.Index))
                 .SetResult(0, TransmitMachine.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("储电箱")
                 .SetIngredian(0, ILibrary.GetCraftId(PlanksBlock.Index)).SetIngredian(1, ILibrary.GetCraftId(InsulatedTinCable.Index)).SetIngredian(2, ILibrary.GetCraftId(PlanksBlock.Index))
                 .SetIngredian(3, ILibrary.GetCraftId(Battery.Index)).SetIngredian(4, ILibrary.GetCraftId(Battery.Index)).SetIngredian(5, ILibrary.GetCraftId(Battery.Index))
                 .SetIngredian(6, ILibrary.GetCraftId(PlanksBlock.Index)).SetIngredian(7, ILibrary.GetCraftId(PlanksBlock.Index)).SetIngredian(8, ILibrary.GetCraftId(PlanksBlock.Index))
                 .SetResult(0, BatBox.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("CESU储电箱")
                 .SetIngredian(0, ILibrary.GetCraftId(BronzePlate.Index)).SetIngredian(1, ILibrary.GetCraftId(InsulatedCopperCable.Index)).SetIngredian(2, ILibrary.GetCraftId(BronzePlate.Index))
                 .SetIngredian(3, ILibrary.GetCraftId(AdvancedBattery.Index)).SetIngredian(4, ILibrary.GetCraftId(AdvancedBattery.Index)).SetIngredian(5, ILibrary.GetCraftId(AdvancedBattery.Index))
                 .SetIngredian(6, ILibrary.GetCraftId(BronzePlate.Index)).SetIngredian(7, ILibrary.GetCraftId(BronzePlate.Index)).SetIngredian(8, ILibrary.GetCraftId(BronzePlate.Index))
                 .SetResult(0, CESUBatBox.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("RE-充电电池")
                 .SetIngredian(0, ILibrary.GetCraftId(InsulatedCopperCable.Index)).SetIngredian(1, ILibrary.GetCraftId(BronzeShell.Index)).SetIngredian(2, ILibrary.GetCraftId(InsulatedCopperCable.Index))
                 .SetIngredian(3, ILibrary.GetCraftId(BronzeShell.Index)).SetIngredian(4, ILibrary.GetCraftId(LeadDust.Index)).SetIngredian(5, ILibrary.GetCraftId(BronzeShell.Index))
                 .SetIngredian(6, ILibrary.GetCraftId(BronzeShell.Index)).SetIngredian(7, ILibrary.GetCraftId(SaltpeterChunkBlock.Index)).SetIngredian(8, ILibrary.GetCraftId(BronzeShell.Index))
                 .SetResult(0, AdvancedBattery.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("手电筒")
                 .SetIngredian(0, ILibrary.GetCraftId(OneLedBlock.Index))
                 .SetIngredian(3, ILibrary.GetCraftId(Battery.Index))
                 .SetIngredian(6, ILibrary.GetCraftId(SwitchBlock.Index))
                 .SetResult(0, FlashLight.Index)
                .SetRemainNeedCheck());
            mekRecipe.Add(new MekRecipe(3, 0, 1, 1).SetName("陨石信号发生器")
                 .SetIngredian(0, ILibrary.GetCraftId(ElectrolyticCore.Index))
                 .SetIngredian(3, ILibrary.GetCraftId(Battery.Index))
                 .SetIngredian(6, ILibrary.GetCraftId(EliteControlCircuit.Index))
                 .SetResult(0, Hohlraum.Index)
                .SetRemainNeedCheck());
        }

        public void GenerateRecipeWidget(CanvasWidget canvas, ComponentEnergyMachine energyMachine, ComponentMiner miner, ref System.Action Tick)
        {
            var horizontal = new StackPanelWidget() { Direction = LayoutDirection.Horizontal ,HorizontalAlignment = WidgetAlignment.Center,VerticalAlignment=WidgetAlignment.Center};
            var vertical = new StackPanelWidget() { Direction = LayoutDirection.Vertical, HorizontalAlignment = WidgetAlignment.Center, VerticalAlignment = WidgetAlignment.Center };
            var gridPanelWidget = new GridPanelWidget() { ColumnsCount = 3, RowsCount = 3, Margin = new Vector2(5) };
            var craftProgress = new MekProgressWidget(MekProgressWidget.ProgessType.installing_right) { Size = new Vector2(36, 36) };
            var RemainSlot = new InventorySlotWidget() { Size = new Vector2(54, 54) };
            var ResultSlot = new InventorySlotWidget() { Size = new Vector2(54, 54), Margin = new Vector2(10, 0) };
            RemainSlot.AssignInventorySlot(energyMachine, 9);
            int num = 0;
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    var craftInventorySlot = new InventorySlotWidget();
                    craftInventorySlot.Margin = new Vector2(2f);
                    craftInventorySlot.AssignInventorySlot(energyMachine, num++);
                    gridPanelWidget.Children.Add(craftInventorySlot);
                    gridPanelWidget.SetWidgetCell(craftInventorySlot, new Point2(j, i));
                }
            }
            horizontal.Children.Add(craftProgress);
            RemainSlot.Children.Add(new LabelWidget() { Text = "...", HorizontalAlignment = WidgetAlignment.Center, Color = new Color(0, 0, 0, 96) });
            horizontal.Children.Add(RemainSlot);
            ResultSlot.AssignInventorySlot(energyMachine, 10);
            horizontal.Children.Add(ResultSlot);
            vertical.Children.Add(gridPanelWidget);
            vertical.Children.Add(horizontal);
            canvas.Children.Add(vertical);
            craftProgress.SetProgress(1f);
        }
    }
}
